// 个人信息字段类型
export const handleType = (i:any) => {
  const dateList = ['startD','endD']
  const selectList = ['edu','degree']
  const textareaList = ['textarea']
  const fileList = ['file']
  if(dateList.includes(i)){
    return 'date'
  }else if(selectList.includes(i)){
    return 'select'
  }else if(textareaList.includes(i)){
    return 'textarea'
  }else if(fileList.includes(i)){
    return 'file'
  }else{
    return 'text'
  }
}

export const handleReadOnly = (i:any) => {
  const readOnlyList = ['startD','endD']
  return readOnlyList.includes(i)
}

export const handleRequired = (i:any) => {
  const requiredList = ['startD','endD']
  return requiredList.includes(i)
}

export const handleLine = (i:any) => {
  const readOnlyList = ['startD','endD']
  return readOnlyList.includes(i)
}

export const handleIsLine = (i:any) => {
  const requiredList = ['startD','endD']
  return requiredList.includes(i)
}

export const handleDataSource = (dataSource:any, isSingle:Boolean = false) => {
  let newDataSource
  // 单版本对象or多版本数组
  if(isSingle){
    newDataSource = Object.keys(dataSource).map((i,n)=>{
      let obj = {
        type: handleType(i),  //字段类型
        title: titleMap.get(i), //字段中文名
        name: i,                //字段名
        value: (dataSource as any)[i],  //字段值
        readonly: handleReadOnly(i),  //只读
        required: handleRequired(i),  //必填
        
        key: `${i}-${n}`
      }
      // 为下拉选择时，字段配置column表示字段值列表，text表示字段显示值
      if(handleType(i) === 'select'){
        // obj.column = 
        // obj.text = getDesFromArr()
      }
      return obj
    })
  }else{
    newDataSource = (dataSource as []).map((item,index)=>{
      return Object.keys(item).map((i,n)=>{
        let obj = {
          type: handleType(i),
          title: titleMap.get(i),
          name: i,
          value: (item as any)[i],
          placeholder: titleMap.get(i),
          readonly: handleReadOnly(i),
          required: handleRequired(i),
          line: handleLine(i),
          isline: handleIsLine(i), 
          key: `${i}-${index}-${n}`
        }
      // 为下拉选择时，字段配置text表示字段显示值
        if(handleType(i) === 'select'){
          // obj.text = getDesFromArr()
          // obj.column = 
        }
        if(handleType(i) === 'file'){
          // obj.text = getDesFromArr()
          // obj.column = 
        }
        return obj
      })
    })
  }
  return newDataSource
}
